package com.zhao.dota.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhao.dota.model.DotaMatch;
import com.zhao.dota.struct.MonthMatches;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MatchMapper extends BaseMapper<DotaMatch> {

    @Select("<script>" +
            "SELECT " +
            " sum( b.playback_time ) as countTimeBySteamId " +
            "  FROM match_player a " +
            "  LEFT JOIN dota_match b ON a.match_id = b.id  " +
            " WHERE " +
            " a.steam_id = #{steamId} " +
            " ORDER BY b.end_time desc" +
            "<if test='limit > 0'>" +
            " LIMIT #{limit}" +
            "</if>" +
            "</script>")
    Double countTimeBySteamId(Long steamId, int limit);

    @Select("select DATE_FORMAT(end_time,'%Y-%m') month,count(*) count from dota_match group by month")
    List<MonthMatches> monthMatches();

}
